package com.handinfo.android.ui.window;

import java.io.DataInputStream;
import java.io.IOException;

import android.graphics.Bitmap;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWLabel;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

/**
 * 战场
 * 
 * @author Administrator
 * 
 */
public class UIBattlefield implements IUIWindows {
	DWFrame m_fail_frame = null;
	DWFrame m_win_frame = null;
	DWFrame m_right_frame = null;
	DWTitle m_win_tit;
	DWTitle m_fail_tit;
	DWBackground m_win_xbj_up_bg;
	DWBackground m_fail_xbj_up_bg;
	DWBackground m_win_xbj_down_bg;
	DWBackground m_fail_xbj_down_bg;

	DWImageBox m_win_ima;
	DWImageBox m_fail_ima;
	Bitmap m_cr_win = null;
	Bitmap m_cr_fail = null;
	Bitmap m_cr_but = null;
	Bitmap m_cr_but_1 = null;
	Bitmap m_cr_countdown = null;

	DWButton m_win_but;
	DWButton m_fail_but;

	Boolean m_flag_1;
	Boolean m_flag_2;
	Boolean m_flag_3;

	public void Battlefield_Win() {
		DWControlsManager.getInstance().removeControl(m_right_frame);
		UIWindows.getInstance().m_main.OpenTaskList();
		UIWindows.getInstance().m_main.showTaskList();

		
		if (DWControlsManager.getInstance().contains(m_win_frame)) {
			if (m_win_frame != null) {
				DWControlsManager.getInstance().removeControl(m_win_frame);
			}
		}
		m_flag_2 = true;
		// //画布
		m_win_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_win_frame.setClickClose(false);
		m_win_frame.setThrough(true);

		// 标题
		m_win_tit = new DWTitle("阵营战场", m_win_frame);
		m_win_frame.addControl(m_win_tit);
		// DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		// m_tit_ima.setNearAnchor(m_win_tit, Tools.HCENTER_VCENTER,
		// Tools.HCENTER_VCENTER, 0, 0);
		// m_win_frame.addControl(m_tit_ima);

		// 上面的小背景
		m_win_xbj_up_bg = new DWBackground(m_win_frame.getShowWidth() - 20,
				m_cr_win.getHeight() + 20);
		m_win_xbj_up_bg.setNearAnchor(m_win_frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, 10 + m_win_tit.getShowHeight() - 20);
		m_win_frame.addControl(m_win_xbj_up_bg);

		// 下面的小背景
		m_win_xbj_down_bg = new DWBackground(m_win_xbj_up_bg.getShowWidth(),
				m_win_frame.getShowHeight() - (m_win_tit.getShowHeight() - 20)
						- m_win_xbj_up_bg.getShowHeight() - 5 - 10 - 20);
		m_win_xbj_down_bg.setNearAnchor(m_win_xbj_up_bg, Tools.LEFT_TOP,
				Tools.LEFT_BOTTOM, 0, 5);
		m_win_frame.addControl(m_win_xbj_down_bg);

		// 上面的textbox
		DWTextbox m_win_name = new DWTextbox("",
				m_win_xbj_up_bg.getShowWidth() - 35,
				m_win_xbj_up_bg.getShowHeight() - 20);
		if (m_flag) {
			// m_win_name.setText("<mark c=00BBFF>" + name2 + "</mark>" + "被" +
			// "<mark c=FFBB11>" + name1 + "</mark>"
			// + "击败" + DWControlTools.CHANGE_ROW +
			// "竞技前分数：" + "<mark c=00BBFF>" + haveScore + "</mark>" + "分" +
			// DWControlTools.CHANGE_ROW +
			// "竞技后得分：" + "<mark c=FF3300>" + addScore + "</mark>" + "分");
			m_win_name.setText("<mark c=00BBFF>" + "[天机]"
					+ "</mark>" + "<mark c=00BBFF>" + Score1 + "</mark>"
					+ "分" + "<mark c=00BBFF>" + "[灵隐]" + "</mark>"
					+ "<mark c=00BBFF>" + Score2 + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW +
					"1." + "<mark c=00BBFF>"
					+ "[" + Reaml[0] + "]" + "</mark>" + "<mark c=FFBB11>" + Name1
					+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren1
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW +
					"2."
					+ "<mark c=00BBFF>" + "[" + Reaml[1] + "]" + "</mark>"
					+ "<mark c=FFBB11>" + Name2 + "</mark>" + ":"
					+ "<mark c=00BBFF>" + Scoren2 + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW +
					"3." + "<mark c=00BBFF>"
					+ "[" + Reaml[2] + "]" + "</mark>" + "<mark c=FFBB11>" + Name3
					+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren3
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW
					+ 
					"<mark c=FFBB11>"
					+ DWGameManager.getInstance().m_role.m_name + "</mark>"
					+ ":" + "<mark c=00BBFF>" + MyScore + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW);
		} else if (!m_flag) {
			m_win_name
					.setText("<mark c=00BBFF>" + name2 + "</mark>" + "被"
							+ "<mark c=FFBB11>" + name1 + "</mark>" + "击败"
							+ DWControlTools.CHANGE_ROW + "<mark c=FFBB11>"
							+ f1name + "</mark>" + "：" + "剩余"
							+ "<mark c=FF3300>" + f1amount + "</mark>" + "人"
							+ DWControlTools.CHANGE_ROW + "<mark c=00BBFF>"
							+ f2name + "</mark>" + "：" + "剩余"
							+ "<mark c=FF3300>" + f2amount + "</mark>" + "人"
							+ DWControlTools.CHANGE_ROW + "竞技前分数："
							+ "<mark c=00BBFF>" + haveScore + "</mark>" + "分"
							+ DWControlTools.CHANGE_ROW + "竞技后得分："
							+ "<mark c=FF3300>" + addScore + "</mark>" + "分");
		}
		m_win_name.setNearAnchor(m_win_xbj_up_bg, Tools.LEFT_VCENTER,
				Tools.LEFT_VCENTER, 15, 0);
		m_win_frame.addControl(m_win_name);

		// 胜利的图片
		m_win_ima = new DWImageBox(m_cr_win);
		m_win_ima.setNearAnchor(m_win_xbj_up_bg, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, -15, 0);
		m_win_frame.addControl(m_win_ima);

		// ///下面布局
		// m_win_but = new DWButton("", m_cr_countdown);
		// m_win_but.setNearAnchor(m_win_xbj_down_bg, Tools.RIGHT_TOP,
		// Tools.RIGHT_TOP, 0, 5);
		// m_win_frame.addControl(m_win_but);

		DWTextbox m_win_text = new DWTextbox("奖励如下："
				+ DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "战功点数："
				+ "</mark>" + zhangong + DWControlTools.CHANGE_ROW
				+ "<mark c=ffc001>" + "经验：" + "</mark>" + exp
				+ DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "金币："
				+ "</mark>" + money + DWControlTools.CHANGE_ROW+"<mark c=ffc001>" + "荣誉："
				+ "</mark>" +rongyu,
				m_win_xbj_down_bg.getShowWidth() - 20,
				m_win_xbj_down_bg.getShowHeight() - m_cr_countdown.getHeight()
						- m_cr_but.getHeight() - 10);
		m_win_text.setNearAnchor(m_win_xbj_down_bg, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, m_cr_countdown.getHeight() + 5);
		m_win_frame.addControl(m_win_text);

		DWButton m_submit = new DWButton("确定", m_cr_but);
		m_submit.setDownImage(m_cr_but_1);
		m_submit.setNearAnchor(m_win_text, Tools.RIGHT_TOP, Tools.RIGHT_BOTTOM,
				0, 5);
		m_win_frame.addControl(m_submit);
		m_submit.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				m_flag_2 = false;
				DWControlsManager.getInstance().removeControl(m_win_frame);
			}
		});

		DWControlsManager.getInstance().addControl(m_win_frame);
		m_flag = true;
	}

	public void Battlefield_Fail() {
		
		DWControlsManager.getInstance().removeControl(m_right_frame);
		UIWindows.getInstance().m_main.OpenTaskList();
		UIWindows.getInstance().m_main.showTaskList();
		
		if (DWControlsManager.getInstance().contains(m_fail_frame)) {
			if (m_fail_frame != null) {
				DWControlsManager.getInstance().removeControl(m_fail_frame);
			}
		}
		m_flag_3 = true;
		// //画布
		m_fail_frame = new DWFrame(DWFrame.FRAME_TYPE_HALF_HCENTER, true);
		m_fail_frame.setClickClose(false);
		m_fail_frame.setThrough(true);
		// 标题
		m_fail_tit = new DWTitle("阵营战场", m_fail_frame);
		m_fail_frame.addControl(m_fail_tit);
		// DWImageBox m_tit_ima = new DWImageBox(m_cr_tit_fail);
		// m_tit_ima.setNearAnchor(m_fail_tit, Tools.HCENTER_VCENTER,
		// Tools.HCENTER_VCENTER, 0, 0);
		// m_fail_frame.addControl(m_tit_ima);

		// 上面的小背景
		m_fail_xbj_up_bg = new DWBackground(m_fail_frame.getShowWidth() - 20,
				m_cr_win.getHeight() + 20);
		m_fail_xbj_up_bg.setNearAnchor(m_fail_frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, 10 + (m_fail_tit.getShowHeight() - 20));
		m_fail_frame.addControl(m_fail_xbj_up_bg);

		// 下面的小背景
		m_fail_xbj_down_bg = new DWBackground(m_fail_xbj_up_bg.getShowWidth(),
				m_fail_frame.getShowHeight()
						- (m_fail_tit.getShowHeight() - 20)
						- m_fail_xbj_up_bg.getShowHeight() - 5 - 10 - 20);
		m_fail_xbj_down_bg.setNearAnchor(m_fail_xbj_up_bg, Tools.LEFT_TOP,
				Tools.LEFT_BOTTOM, 0, 5);
		m_fail_frame.addControl(m_fail_xbj_down_bg);

		// 上面的textbox
		DWTextbox m_fail_name = new DWTextbox("",
				m_fail_xbj_up_bg.getShowWidth() - 35,
				m_fail_xbj_up_bg.getShowHeight() - 20);
		if (m_flag) {
			// m_fail_name.setText("<mark c=00BBFF>" + name1 + "</mark>" + "被" +
			// "<mark c=FFBB11>" + name2 + "</mark>"
			// + "击败" + DWControlTools.CHANGE_ROW +
			// "竞技前分数：" + "<mark c=00BBFF>" + haveScore + "</mark>" + "分" +
			// DWControlTools.CHANGE_ROW +
			// "竞技后得分：" + "<mark c=FF3300>" + addScore + "</mark>" + "分");
			m_fail_name.setText("<mark c=00BBFF>" + "[天机]"
					+ "</mark>" + "<mark c=00BBFF>" + Score1 + "</mark>"
					+ "分" + "<mark c=00BBFF>" + "[灵隐]" + "</mark>"
					+ "<mark c=00BBFF>" + Score2 + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW +
					"1." + "<mark c=00BBFF>"
					+ "[" + Reaml[0] + "]" + "</mark>" + "<mark c=FFBB11>" + Name1
					+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren1
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW +
					"2."
					+ "<mark c=00BBFF>" + "[" + Reaml[1] + "]" + "</mark>"
					+ "<mark c=FFBB11>" + Name2 + "</mark>" + ":"
					+ "<mark c=00BBFF>" + Scoren2 + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW +
					"3." + "<mark c=00BBFF>"
					+ "[" + Reaml[2] + "]" + "</mark>" + "<mark c=FFBB11>" + Name3
					+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren3
					+ "</mark>" + "分" + DWControlTools.CHANGE_ROW
					+ 
					"<mark c=FFBB11>"
					+ DWGameManager.getInstance().m_role.m_name + "</mark>"
					+ ":" + "<mark c=00BBFF>" + MyScore + "</mark>" + "分"
					+ DWControlTools.CHANGE_ROW);
		} else if (!m_flag) {
			m_fail_name
					.setText("<mark c=00BBFF>" + name1 + "</mark>" + "被"
							+ "<mark c=FFBB11>" + name2 + "</mark>" + "击败"
							+ DWControlTools.CHANGE_ROW + "<mark c=FFBB11>"
							+ f1name + "</mark>" + "：" + "剩余"
							+ "<mark c=FF3300>" + f1amount + "</mark>" + "人"
							+ DWControlTools.CHANGE_ROW + "<mark c=00BBFF>"
							+ f2name + "</mark>" + "：" + "剩余"
							+ "<mark c=FF3300>" + f2amount + "</mark>" + "人"
							+ DWControlTools.CHANGE_ROW + "竞技前分数："
							+ "<mark c=FFBB11>" + haveScore + "</mark>" + "分"
							+ DWControlTools.CHANGE_ROW + "竞技后得分："
							+ "<mark c=55FF00>" + addScore + "</mark>" + "分");
		}
		m_fail_name.setNearAnchor(m_fail_xbj_up_bg, Tools.LEFT_VCENTER,
				Tools.LEFT_VCENTER, 15, 0);
		m_fail_frame.addControl(m_fail_name);

		// 失败的图片
		m_fail_ima = new DWImageBox(m_cr_fail);
		m_fail_ima.setNearAnchor(m_fail_xbj_up_bg, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, -15, 0);
		m_fail_frame.addControl(m_fail_ima);

		// ///下面布局
		// m_fail_but = new DWButton("", m_cr_countdown);
		// m_fail_but.setNearAnchor(m_fail_xbj_down_bg, Tools.RIGHT_TOP,
		// Tools.RIGHT_TOP, 0, 5);
		// m_fail_frame.addControl(m_fail_but);

		DWTextbox m_fail_text = new DWTextbox("奖励如下："
				+ DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "战功点数："
				+ "</mark>" + zhangong + DWControlTools.CHANGE_ROW
				+ "<mark c=ffc001>" + "经验：" + "</mark>" + exp
				+ DWControlTools.CHANGE_ROW + "<mark c=ffc001>" + "金币："
				+ "</mark>" + money + DWControlTools.CHANGE_ROW+"<mark c=ffc001>" + "荣誉："
				+ "</mark>" +rongyu,m_fail_xbj_down_bg.getShowWidth() - 20,
				m_fail_xbj_down_bg.getShowHeight() - m_cr_countdown.getHeight()
						- m_cr_but.getHeight() - 10);

		m_fail_text.setNearAnchor(m_fail_xbj_down_bg, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 10, m_cr_countdown.getHeight() + 5);
		m_fail_frame.addControl(m_fail_text);

		DWButton m_submit = new DWButton("确定", m_cr_but);
		m_submit.setDownImage(m_cr_but_1);
		m_submit.setNearAnchor(m_fail_text, Tools.RIGHT_TOP,
				Tools.RIGHT_BOTTOM, 0, 5);
		m_fail_frame.addControl(m_submit);
		m_submit.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				m_flag_3 = false;
				DWControlsManager.getInstance().removeControl(m_fail_frame);
			}
		});

		DWControlsManager.getInstance().addControl(m_fail_frame);
		m_flag = true;
	}

	// 任务显示区换为提示战场分数
	public DWBackground m_task_background = null;
	public DWListbox m_task_listBox = null;

	public void Battlefield_right() {
		UIWindows.getMain().hideTaskList();
		// //画布
		m_right_frame = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
//				DWFrame(DWGameManager.Screen_Width
//				- DWGameManager.Screen_Width / 5 + 30,
//				DWGameManager.Screen_Height * 13 / 48,
//				DWGameManager.Screen_Width / 5 + 30,
//				DWGameManager.Screen_Height * 13 / 48);
		m_right_frame.m_null_frame = true;
		m_right_frame.setClickClose(false);
		m_right_frame.setThrough(true);
		m_right_frame.setShield(true);

		 m_task_background = new DWBackground(DWGameManager.Screen_Width / 5 +
		 30,
		 DWGameManager.Screen_Height * 13 / 48);
		 m_task_background.setNearAnchor(m_right_frame, Tools.RIGHT_TOP,
		 Tools.RIGHT_TOP, 0,
		 DWGameManager.Screen_Height * 13 / 48);

		DWTextbox m_name = new DWTextbox("",
				DWGameManager.Screen_Width / 5 + 20,
				DWGameManager.Screen_Height * 13 / 48 - 4);

		m_name.setText("<mark c=00BBFF>" + "[天机]"
				+ "</mark>" + "<mark c=00BBFF>" + Score1 + "</mark>"
				+ "分" + DWControlTools.CHANGE_ROW + "<mark c=00BBFF>" + "[灵隐]" + "</mark>"
				+ "<mark c=00BBFF>" + Score2 + "</mark>" + "分"
				+ DWControlTools.CHANGE_ROW +
				"1." + "<mark c=00BBFF>"
				+ "[" + Reaml[0] + "]" + "</mark>" + "<mark c=FFBB11>" + Name1
				+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren1
				+ "</mark>" + "分" + DWControlTools.CHANGE_ROW +
				"2."
				+ "<mark c=00BBFF>" + "[" + Reaml[1] + "]" + "</mark>"
				+ "<mark c=FFBB11>" + Name2 + "</mark>" + ":"
				+ "<mark c=00BBFF>" + Scoren2 + "</mark>" + "分"
				+ DWControlTools.CHANGE_ROW +
				"3." + "<mark c=00BBFF>"
				+ "[" + Reaml[2] + "]" + "</mark>" + "<mark c=FFBB11>" + Name3
				+ "</mark>" + ":" + "<mark c=00BBFF>" + Scoren3
				+ "</mark>" + "分" + DWControlTools.CHANGE_ROW
				+ 
				"<mark c=FFBB11>"
				+ DWGameManager.getInstance().m_role.m_name + "</mark>"
				+ ":" + "<mark c=00BBFF>" + MyScore + "</mark>" + "分"
				+ DWControlTools.CHANGE_ROW);

		m_name.setNearAnchor(m_task_background, Tools.LEFT_VCENTER,
				Tools.LEFT_VCENTER, 5, 2);

		m_right_frame.addControl(m_task_background);
		m_right_frame.addControl(m_name);

		DWControlsManager.getInstance().addControl(m_right_frame);
	}

	public void init() {
		// 加载图片
		m_cr_tit = UIWindows.createImage("/img/newui/jingjichangbt.gnp");
		m_cr_tit_win = UIWindows.createImage("/img/newui/jingjishenglibt.gnp");
		m_cr_tit_fail = UIWindows.createImage("/img/newui/jingjishibaibt.gnp");
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp"); // //按钮的图片
		m_cr_but_1 = UIWindows.createImage("/img/newui/anniu_6ax.gnp"); // //按钮点击后变的图片
		m_cr_win = UIWindows.createImage("/img/newui/fubensl_1.gnp");
		m_cr_fail = UIWindows.createImage("/img/newui/fubensb_1.gnp");
		m_cr_countdown = UIWindows
				.createImage("/img/newui/fubenshenglidmk_1.gnp");
		m_cr_tuichu = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");// 叉键退出
		
		Reaml=new String[3];
	}

	DWFrame m_count_frame = null;
	DWImageBox m_tuichu_ima;
	DWButton m_count_ima_but;
	DWTextbox m_count_text;
	DWTextbox m_text;
	Bitmap m_cr_tuichu = null;
	DWBackground m_count_xbj;
	DWButton m_submit_but;
	Bitmap m_cr_tit = null;
	Bitmap m_cr_tit_win = null;
	Bitmap m_cr_tit_fail = null;

	public void Count_down() {
		
		if (DWControlsManager.getInstance().contains(m_count_frame)) {
			if (m_count_frame != null) {
				DWControlsManager.getInstance().removeControl(m_count_frame);
			}
		}
		m_flag_1 = true;
		m_count_frame = new DWFrame(400, 300);
		m_count_frame.setClickClose(false);

		DWTitle m_tit = new DWTitle("", m_count_frame);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_tit, Tools.HCENTER_VCENTER,
				Tools.HCENTER_VCENTER, 0, 0);

		m_count_xbj = new DWBackground(m_count_frame.getShowWidth() - 30,
				m_count_frame.getShowHeight() - (m_tit.getShowHeight() - 20)
						- 25);
		m_count_xbj.setNearAnchor(m_count_frame, Tools.LEFT_TOP,
				Tools.LEFT_TOP, 15, 10 + (m_tit.getShowHeight() - 20));

		m_tuichu_ima = new DWImageBox(m_cr_tuichu);
		m_tuichu_ima.setNearAnchorUn(m_tit, Tools.RIGHT_VCENTER,
				Tools.RIGHT_VCENTER, 0, 0);
		m_tuichu_ima.addListener(m_tuichu_lis);
		m_tuichu_ima.setTouchZoomIn(20, 20);

		m_count_ima_but = new DWButton("", m_cr_countdown);
		m_count_ima_but.setNearAnchor(m_count_xbj, Tools.RIGHT_TOP,
				Tools.RIGHT_TOP, 0, 5);

		m_count_text = new DWTextbox("阵营战场已经找到对手，现在进入阵营战场？",
				m_count_xbj.getShowWidth() - 80, m_count_xbj.getShowHeight()
						- m_cr_but.getHeight()
						- m_count_ima_but.getShowHeight() - 30);
		m_count_text.setNearAnchor(m_count_xbj, Tools.LEFT_TOP, Tools.LEFT_TOP,
				40, m_count_ima_but.getShowHeight() + 15);

		m_submit_but = new DWButton("确定", m_cr_but);
		m_submit_but.setDownImage(m_cr_but_1);
		m_submit_but.setNearAnchor(m_count_text, Tools.RIGHT_TOP,
				Tools.RIGHT_BOTTOM, 0, 15);
		m_submit_but.addListener(m_submit_lis);

		m_count_frame.addControl(m_tit);
		m_count_frame.addControl(m_tit_ima);
		m_count_frame.addControl(m_count_xbj);
		m_count_frame.addControl(m_tuichu_ima);
		m_count_frame.addControl(m_count_ima_but);
		m_count_frame.addControl(m_count_text);
		m_count_frame.addControl(m_submit_but);
		DWControlsManager.getInstance().addControl(m_count_frame);

	}

	private DWListener m_submit_lis = new DWListener() {

		public void OnDoubleClick() {
		}

		public void OnClick() {
			UIWindows.getMain().closeTaskList();
			UIWindows.getMain().hideTaskList();//隐藏任务窗口
			
			DWGameManager
					.getInstance()
					.getSendMessage()
					.sendARENREQUEST(
							(byte) 1,
							UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
									.getInstance().m_assistant.m_index].m_type,
							id);
			DWControlsManager.getInstance().removeControl(m_count_frame);

			Tools.debugPrintln("发送进入阵营战场的类型："
					+ UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
							.getInstance().m_assistant.m_index].m_type);
			m_flag_1 = false;
			if (DWControlsManager.getInstance().contains(
					UIWindows.getInstance().m_assistant.m_assistant_frame)) {
				DWControlsManager.getInstance().removeControl(
						UIWindows.getInstance().m_assistant.m_assistant_frame);
			}
		}
	};
	private DWListener m_tuichu_lis = new DWListener() {

		public void OnDoubleClick() {

		}

		public void OnClick() {
			final DWMessageBox mb = new DWMessageBox("温馨提示", "确定退出阵营战场？");
			mb.addListener(new DWListener() {

				public void OnDoubleClick() {

				}

				public void OnClick() {
					if (mb.getResult() == DWMessageBox.SOFTKEY_OK) {
						m_flag_1 = false;
						DWGameManager
								.getInstance()
								.getSendMessage()
								.sendARENREQUEST(
										(byte) 0,
										UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
												.getInstance().m_assistant.m_index].m_type,
										id);
						Tools.debugPrintln("发送进入阵营战场的类型："
								+ UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_type);
						DWControlsManager.getInstance().removeControl(mb);
						DWControlsManager.getInstance().removeControl(
								m_count_frame);

						UIWindows.getInstance().m_assistant.m_data_text[UIWindows
								.getInstance().m_assistant.m_index]
								.setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
										.getInstance().m_assistant.m_index].m_description);
						UIWindows.getInstance().m_assistant.m_but[UIWindows
								.getInstance().m_assistant.m_index]
								.setName("立即参加");
					} else if (mb.getResult() == DWMessageBox.SOFTKEY_BACK) {
						DWControlsManager.getInstance().removeControl(mb);
					}
				}
			});
			DWControlsManager.getInstance().addControl(mb);
		}
	};

	public void open(byte index) {
//		index = 1;
		switch (index) {
		case 0:
			Count_down();
			break;
		case 1:
			Battlefield_Win();
			break;
		case 2:
			Battlefield_Fail();
			break;
		}
//		 DWControlsManager.getInstance().removeControl(m_right_frame);
//		 Battlefield_right();
	}

	public void close(byte index) {
	}

	public void dispose() {
	}

	DWFrame m_line_frame = null;
	DWTitle m_line_tit;
	DWBackground m_line_xbj;
	DWTextbox m_line_text;
	DWButton m_line_but_count;
	DWButton m_line_but_submit;
	DWImageBox m_line_tc;
	/**
	 * 是否同意进入竞技场
	 * 
	 * @param dis
	 * @throws IOException
	 */
	long id;

	public void recvIsImmediatelyInto(DataInputStream dis) throws IOException {
		Tools.debugPrintln("是否进入阵营战场？");
		byte state = dis.readByte(); // 1个人，２家族
		id = dis.readLong(); // id
		timer = dis.readByte();// 倒计时秒数
		m_start_time = System.currentTimeMillis();// 读取时截取系统时间
		Tools.debugPrintln("id:" + id + "timer:" + timer);
		Count_down();
		if (DWControlsManager.getInstance().contains(
				UIWindows.getInstance().m_assistant.m_assistant_frame)) {
			UIWindows.getInstance().m_assistant.m_data_text[UIWindows
					.getInstance().m_assistant.m_index].setName(UIWindows
					.getInstance().m_assistant.m_activity_list[UIWindows
					.getInstance().m_assistant.m_index].m_description);
			UIWindows.getInstance().m_assistant.m_but[UIWindows.getInstance().m_assistant.m_index]
					.setName("立即参加");
			UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
					.getInstance().m_assistant.m_index].m_count_donw = 0;
		}
	}

	/**
	 * \ 倒计时
	 * 
	 * @param dis
	 * @throws IOException
	 */
	public void recvDJS(DataInputStream dis) throws IOException {
		byte state = dis.readByte();// 1：进入竞技场，准备战斗前
		if (state == 1) {
			short time = dis.readShort(); //
		}
	}

	private byte timer;
	private long m_start_time = 0;

	public void Timer() {
		if (DWControlsManager.getInstance().contains(m_count_frame)) {
			if (timer > 0) {
				if (m_start_time == 0) {
					m_start_time = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (timer - (currentTime - m_start_time) / 1000);
				if (index < 0) {
					m_start_time = 0;
				} else {
					m_count_ima_but.setName(Integer.toString(index));
					if (m_flag_1 == true) {
						if (index == 0) {
							m_start_time = 0;
							timer = 0;
							DWControlsManager.getInstance().removeControl(
									m_count_frame);
							if (DWControlsManager
									.getInstance()
									.contains(
											UIWindows.getInstance().m_assistant.m_assistant_frame)) {
								UIWindows.getInstance().m_assistant.m_data_text[UIWindows
										.getInstance().m_assistant.m_index]
										.setName(UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
												.getInstance().m_assistant.m_index].m_description);
								UIWindows.getInstance().m_assistant.m_but[UIWindows
										.getInstance().m_assistant.m_index]
										.setName("立即参加");
							}
							DWGameManager
									.getInstance()
									.getSendMessage()
									.sendARENREQUEST(
											(byte) 0,
											UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
													.getInstance().m_assistant.m_index].m_type,
											id);
							Tools.debugPrintln("退出进入阵营战场的类型："
									+ UIWindows.getInstance().m_assistant.m_activity_list[UIWindows
											.getInstance().m_assistant.m_index].m_type);
						}
					}
				}
			}
		}
	}

	public void logic() {
		Timer();
		Over_win();
		Over_fail();
	}

	int Score1;// 天机
	int Score2;// 灵隐
	byte count;//判断发送过来多少个玩家
	byte Reaml1;// 阵营
	String Name1;// 玩家
	int Scoren1;// 分数
	byte Reaml2;// 阵营
	String Name2;// 玩家
	int Scoren2;// 分数
	byte Reaml3;// 阵营
	String Name3;// 玩家
	int Scoren3;// 分数
	int MyScore;// 自己分数
	String Reaml[];// 显示玩家排名的阵营
	
	

	public void recvScore(DataInputStream dis) throws IOException {
		
		Score1 = dis.readInt();// 天机分数
		Score2 = dis.readInt();// 灵隐分数
		count = dis.readByte();// 判断发送过来多少个玩家
		
		Reaml=new String[3];
		Tools.debugPrintln("count:" + count);
		if(count>3){
			count=3;
		}

		switch (count) {
		case 1:
			Reaml1 = dis.readByte();// 第一名阵营
			Name1 = dis.readUTF();// 第一名玩家
			Scoren1 = dis.readInt();// 第一名玩家分数
			if(Reaml1==1){
				Reaml[0]="灵隐";
			}else{
				Reaml[0]="天机";
			}
			Tools.debugPrintln("Score1:" + Score1);
			Tools.debugPrintln("Score2:" + Score2);
			Tools.debugPrintln("Reaml1:" + Reaml1);
			Tools.debugPrintln("Name1:" + Name1);
			Tools.debugPrintln("Scoren1:" + Scoren1);

			break;
		case 2:
			Reaml1 = dis.readByte();// 第一名阵营
			Name1 = dis.readUTF();// 第一名玩家
			Scoren1 = dis.readInt();// 第一名玩家分数
			Reaml2 = dis.readByte();// 第二名阵营
			Name2 = dis.readUTF();// 第二名玩家
			Scoren2 = dis.readInt();// 第二名玩家分数
			
			if(Reaml1==1){
				Reaml[0]="灵隐";
			}else{
				Reaml[0]="天机";
			}
			if(Reaml2==1){
				Reaml[1]="灵隐";
			}else{
				Reaml[1]="天机";
			}
			Tools.debugPrintln("Score1:" + Score1);
			Tools.debugPrintln("Score2:" + Score2);
			Tools.debugPrintln("Reaml1:" + Reaml1);
			Tools.debugPrintln("Name1:" + Name1);
			Tools.debugPrintln("Scoren1:" + Scoren1);
			Tools.debugPrintln("Reaml2:" + Reaml2);
			Tools.debugPrintln("Name2:" + Name2);
			Tools.debugPrintln("Scoren2:" + Scoren2);
			break;
		case 3:
			Reaml1 = dis.readByte();// 第一名阵营
			Name1 = dis.readUTF();// 第一名玩家
			Scoren1 = dis.readInt();// 第一名玩家分数
			Reaml2 = dis.readByte();// 第二名阵营
			Name2 = dis.readUTF();// 第二名玩家
			Scoren2 = dis.readInt();// 第二名玩家分数
			Reaml3 = dis.readByte();// 第三名阵营
			Name3 = dis.readUTF();// 第三名玩家
			Scoren3 = dis.readInt();// 第三名分数


	
			Tools.debugPrintln("Score1:" + Score1);
			Tools.debugPrintln("Score2:" + Score2);
			Tools.debugPrintln("Reaml1:" + Reaml1);
			Tools.debugPrintln("Name1:" + Name1);
			Tools.debugPrintln("Scoren1:" + Scoren1);
			Tools.debugPrintln("Reaml2:" + Reaml2);
			Tools.debugPrintln("Name2:" + Name2);
			Tools.debugPrintln("Scoren2:" + Scoren2);
			Tools.debugPrintln("Reaml3:" + Reaml3);
			Tools.debugPrintln("Name3:" + Name3);
			Tools.debugPrintln("Scoren3:" + Scoren3);


			if(Reaml1==1){
				Reaml[0]="灵隐";
			}else{
				Reaml[0]="天机";
			}
			if(Reaml2==1){
				Reaml[1]="灵隐";
			}else{
				Reaml[1]="天机";
			}
			if(Reaml3==1){
				Reaml[2]="灵隐";
			}else{
				Reaml[2]="天机";
			}
			break;
			

		default:
			break;
		}
		
	
		MyScore = dis.readInt();// 自己分数
		Tools.debugPrintln("MyScore:" + MyScore);
		
		DWControlsManager.getInstance().removeControl(m_right_frame);
		Battlefield_right();
		
	
	}

	/**
	 * 竞技场结算界面
	 * 
	 * @param dis
	 * @throws IOException
	 */
	String name1;
	String name2;
	int haveScore;// 原有分数
	int addScore;// 新加分数
	int zhangong; // 奖励战功
	int exp;// 经验
	int money;
	int rongyu;
	byte haveNext; // 可再参加次数
	byte CountDown; // 秒数
	byte m_over_1;
	private long m_over_count_1 = 0;
	private long m_over_count_2 = 0;

	public void recvOVER(DataInputStream dis) throws IOException {
		byte state = dis.readByte();// 1胜利　，0　失败
//		name1 = dis.readUTF();
//		name2 = dis.readUTF();
//		haveScore = dis.readInt();// 原有分数
//		addScore = dis.readInt();// 新加分数
		zhangong = dis.readInt(); // 奖励战功
		exp = dis.readInt();// 经验
		money = dis.readInt();// 金币
		rongyu = dis.readInt(); ///荣誉
//		haveNext = dis.readByte(); // 可再参加次数
//		CountDown = dis.readByte(); // 秒数

		Tools.debugPrintln("CountDown:" + CountDown);
		Tools.debugPrintln("haveNext:" + haveNext);
		Tools.debugPrintln("name1:" + name1);
		Tools.debugPrintln("name2:" + name2);
		m_over_1 = CountDown;
		m_over_count_1 = System.currentTimeMillis();// 读取时截取系统时间
		m_over_count_2 = System.currentTimeMillis();// 读取时截取系统时间
		if (state == 1) {
			Battlefield_Win();
			m_win_but.setName(CountDown + "");
		} else if (state == 0) {
			Battlefield_Fail();
		}
		UIWindows.getInstance().m_main.m_jingji_bg.setShow(false);
		UIWindows.getInstance().m_main.m_jingji_tb.setShow(false);
		UIWindows.getInstance().m_main.OpenTaskList();
		UIWindows.getInstance().m_main.showTaskList();
	}

	public void Over_win() {
		if (DWControlsManager.getInstance().contains(m_win_frame)) {
			if (CountDown > 0) {
				if (m_over_count_1 == 0) {
					m_over_count_1 = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (CountDown - (currentTime - m_over_count_1) / 1000);
				if (index < 0) {
					m_over_count_1 = 0;
				} else {
					m_win_but.setName(index + "");
					if (m_flag_2 == true) {
						if (index == 0) {
							DWControlsManager.getInstance().removeControl(
									m_win_frame);
							CountDown = 0;
						}
					}
				}
			}
		}
	}

	public void Over_fail() {
		if (DWControlsManager.getInstance().contains(m_fail_frame)) {
			if (m_over_1 > 0) {
				if (m_over_count_2 == 0) {
					m_over_count_2 = System.currentTimeMillis();// 读取时截取系统时间
				}
				long currentTime = System.currentTimeMillis();// 当前系统时间
				int index = (int) (m_over_1 - (currentTime - m_over_count_2) / 1000);
				if (index < 0) {
					m_over_count_2 = 0;
				} else {
					m_fail_but.setName(index + "");
					if (m_flag_3 == true) {
						if (index == 0) {
							DWControlsManager.getInstance().removeControl(
									m_fail_frame);
							m_over_1 = 0;
						}
					}
				}
			}
		}
	}

	/**
	 * 读取家族竞技场剩余人数
	 * 
	 * @param dis
	 * @throws IOException
	 */
	/**
	 * 家族竞技场
	 */
	String f1name;
	byte f1amount;
	String f2name;
	byte f2amount;
	boolean m_flag = true;

	@SuppressWarnings("static-access")
	public void recvFamilyArenaRoleAmount(DataInputStream dis)
			throws IOException {
		f1name = dis.readUTF();
		f1amount = dis.readByte();
		f2name = dis.readUTF();
		f2amount = dis.readByte();
		m_flag = false;
		UIWindows.getInstance().m_main.closeTaskList();
		UIWindows.getInstance().m_main.m_jingji_bg.setShow(true);
		UIWindows.getInstance().m_main.m_jingji_tb.setShow(true);
		UIWindows.getInstance().m_main.m_jingji_tb.setText("<mark c=FFBB11>"
				+ f1name + "</mark>" + "：" + "剩余" + "<mark c=FF3300>"
				+ f1amount + "</mark>" + "人" + DWControlTools.CHANGE_ROW
				+ "<mark c=00BBFF>" + f2name + "</mark>" + "：" + "剩余"
				+ "<mark c=FF3300>" + f2amount + "</mark>" + "人");
		Tools.debugPrintln("家族1：" + f1name);
		Tools.debugPrintln("1人数：" + f1amount);
		Tools.debugPrintln("家族2：" + f2name + "1人数：");
		Tools.debugPrintln("2人数：" + f2amount);
	}
}
